﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace BookStore.Shops
{
    public class ShopFunctionModule :
    #region
        //    CrudAppService<
        //        Shop,
        //        ShopDto,
        //        int,
        //        PagedAndSortedResultRequestDto,
        //        CreateUpdateShopDto>,
        //    IShopFunctionModule
        //{
        //    public ShopFunctionModule(IRepository<Shop, int> repository)
        //        : base(repository)
        //    {

        //    }
        //}
    #endregion

        CrudAppService<
            Shop,
            ShopDto,
            int,
            QueryShopAnnexedDto,
            CreateUpdateShopDto>,
        IShopFunctionModule
    {
        private IRepository<Shop, int> _repository;
        private IRepository<ShopAnnexed, int> _annrepository;
        public ShopFunctionModule(IRepository<Shop, int> repository, IRepository<ShopAnnexed, int> annrepository)
            : base(repository)
        {
            _repository = repository;
            _annrepository = annrepository;
        }
        [HttpGet("api/app/shop/GetList")]
        public async Task<PagedResultDto<ShopAndAnnexedDto>> GetList(QueryShopAnnexedDto input)
        {
            var quer = from shop in await _repository.GetListAsync()//*///GetPagedListAsync(input.SkipCount, input.MaxResultCount, input.Sorting)
                       join a in await _annrepository.GetListAsync()
                       on shop.ShopType equals a.AnnexedId
                       select new ShopAndAnnexedDto
                       {
                           Id = shop.Id,
                           ShopName = shop.ShopName,
                           ShopType = a.AnnexedId,
                           ShopBrand = a.Id,
                           ShopDescription = shop.ShopDescription,
                           ShopImg = shop.ShopImg,
                           ShopPrice = shop.ShopPrice,
                           ShopMemberprice = shop.ShopMemberprice,
                       };
            PagedResultDto<ShopAndAnnexedDto> obj = new PagedResultDto<ShopAndAnnexedDto>();
            obj.Items = quer.ToList();
            obj.TotalCount = (await _repository.GetListAsync()).Count();
            return obj;
        }
    }
}
